<?php

namespace models\DAO;

use models\Exception\DAO\ModelDriverException;
use models\Exception\DAO\ModelException;
use models\Exception\DAO\ModelReflectionException;
use models\Exception\DAO\ModelSqlException;


/**
 * @SWG\Swagger(
 *     @SWG\Definition(
 *          type="object",
 *          definition="memberSingleData",
 *          required={"errno", "errmsg", "data"},
 *          @SWG\Property(property="errno", type="integer", format="int32", description="编码"),
 *          @SWG\Property(property="errmsg", type="string", format="string", description="错误提示信息"),
 *          @SWG\Property(property="result", type="object", ref="#/definitions/memberSingleObj")
 *     ),
 *     @SWG\Definition(
 *          type="object",
 *          definition="memberSingleObj",
 *          @SWG\Property(property="data", type="object", ref="#/definitions/memberSingle")
 *     ),
 *     @SWG\Definition(
 *          type="object",
 *          definition="memberListData",
 *          required={"errno", "errmsg", "result"},
 *          @SWG\Property(property="errno", type="integer", format="int32", description="编码"),
 *          @SWG\Property(property="errmsg", type="string", format="string", description="错误提示信息"),
 *          @SWG\Property(property="result", ref="#/definitions/memberListObj"),
 *     ),
 *     @SWG\Definition(
 *          type="object",
 *          definition="memberListObj",
 *          @SWG\Property(property="data", type="object", ref="#/definitions/memberData"),
 *          @SWG\Property(property="meta", ref="#/definitions/meta")
 *     ),
 *     @SWG\Definition(
 *          type="array",
 *          definition="memberData",
 *          @SWG\Items(
 *              title="data", ref="#/definitions/memberSingle"
 *          )
 *     ),
 *     @SWG\Definition(
 *          type="object",
 *          definition="memberSingle",
 *          @SWG\Property(property="id", type="integer", format="int32",  description="主键"),
 *          @SWG\Property(property="uuid", type="string", format="string",  description="uuid"),
 *          @SWG\Property(property="mobile", type="string", format="string",  description="手机号码"),
 *          @SWG\Property(property="nickname", type="string", format="string",  description="昵称"),
 *          @SWG\Property(property="password", type="string", format="string",  description="密码"),
 *          @SWG\Property(property="pay_password", type="string", format="string",  description="支付密码"),
 *          @SWG\Property(property="avatar", type="string", format="string",  description="头像url"),
 *          @SWG\Property(property="parent", type="integer", format="int32",  description="上级用户"),
 *          @SWG\Property(property="device_no", type="string", format="string",  description="设备号"),
 *          @SWG\Property(property="registration_id", type="string", format="string",  description="极光推送"),
 *          @SWG\Property(property="device_type", type="integer", format="int32",  description="设备类型(1为IOS,2为Android,默认为1)"),
 *          @SWG\Property(property="stats", type="integer", format="int32",  description="用户状态(0为禁止登陆,1为允许登陆,2为第三方登录后再与未绑定过第三方账号的手机登录账号进行绑定的作废账号,默认1)"),
 *          @SWG\Property(property="coupon_amount", type="string", format="string",  description="拼团订单成功总金额"),
 *          @SWG\Property(property="coupon_profit", type="string", format="string",  description="用户参与拼团为平台创造的利润"),
 *          @SWG\Property(property="tb_amount", type="string", format="string",  description="淘宝订单金额"),
 *          @SWG\Property(property="integral", type="string", format="string",  description="积分"),
 *          @SWG\Property(property="balance", type="string", format="string",  description="可提现余额"),
 *          @SWG\Property(property="withdraw", type="string", format="string",  description="提现金额"),
 *          @SWG\Property(property="coupon_platform_income", type="string", format="string",  description="该用户通过拼团给平台创造的收入"),
 *          @SWG\Property(property="direct", type="integer", format="int32",  description="直属好友数"),
 *          @SWG\Property(property="indirect", type="integer", format="int32",  description="间接好友数"),
 *          @SWG\Property(property="coupon_order_number", type="integer", format="int32",  description="拼团订单数"),
 *          @SWG\Property(property="coupon_success_order_num", type="integer", format="int32",  description="拼团成功订单数"),
 *          @SWG\Property(property="return_order_number", type="integer", format="int32",  description="退货订单数"),
 *          @SWG\Property(property="refund_order_number", type="integer", format="int32",  description="退款订单数"),
 *          @SWG\Property(property="login_times", type="integer", format="int32",  description="登陆次数"),
 *          @SWG\Property(property="last_login_time", type="string", format="string",  description="上次登陆时间"),
 *          @SWG\Property(property="last_login_ip", type="string", format="string",  description="上次登陆所使用的ip"),
 *          @SWG\Property(property="created_at", type="string", format="string",  description="注册时间"),
 *     )
 * )
 */
class MemberModel extends BaseModel{
    /** 
     * 主键
     */
    public $id = null;

    /** 
     * uuid
     */
    public $uuid = null;

    /** 
     * 手机号码
     */
    public $mobile = null;

    /** 
     * 昵称
     */
    public $nickname = null;

    /** 
     * 密码
     */
    public $password = null;

    /** 
     * 支付密码
     */
    public $pay_password = null;

    /** 
     * 头像url
     */
    public $avatar = null;

    /** 
     * 上级用户
     */
    public $parent = null;

    /** 
     * 设备号
     */
    public $device_no = null;

    /** 
     * 极光推送
     */
    public $registration_id = null;

    /** 
     * 设备类型(1为IOS,2为Android,默认为1)
     */
    public $device_type = null;

    /** 
     * 用户状态(0为禁止登陆,1为允许登陆,2为第三方登录后再与未绑定过第三方账号的手机登录账号进行绑定的作废账号,默认1)
     */
    public $stats = null;

    /** 
     * 拼团订单成功总金额
     */
    public $coupon_amount = null;

    /** 
     * 用户参与拼团为平台创造的利润
     */
    public $coupon_profit = null;

    /** 
     * 淘宝订单金额
     */
    public $tb_amount = null;

    /** 
     * 积分
     */
    public $integral = null;

    /** 
     * 可提现余额
     */
    public $balance = null;

    /** 
     * 提现金额
     */
    public $withdraw = null;

    /** 
     * 该用户通过拼团给平台创造的收入
     */
    public $coupon_platform_income = null;

    /** 
     * 直属好友数
     */
    public $direct = null;

    /** 
     * 间接好友数
     */
    public $indirect = null;

    /** 
     * 拼团订单数
     */
    public $coupon_order_number = null;

    /** 
     * 拼团成功订单数
     */
    public $coupon_success_order_num = null;

    /** 
     * 退货订单数
     */
    public $return_order_number = null;

    /** 
     * 退款订单数
     */
    public $refund_order_number = null;

    /** 
     * 登陆次数
     */
    public $login_times = null;

    /** 
     * 上次登陆时间
     */
    public $last_login_time = null;

    /** 
     * 上次登陆所使用的ip
     */
    public $last_login_ip = null;

    /** 
     * 注册时间
     */
    public $created_at = null;
    /** 
     * DAO对象
     */
    public $obj = '';

    /** 
     * DAO对象数组
     */
    public $data = [];

    /** 
     * 翻页对象
     */
    public $meta = null;

    /** 
     * 当前页
     */
    public $page = 1;

    /** 
     * 每页显示条数
     */
    public $page_size = 10;

    /** 
     * 主键数组
     */
    public $primary_key_arr = ["id"];

    /** 
     * 自增字段数组
     */
    public $auto_increment_key_arr = ["id"];

    /** 
     * 唯一字段
     */
    public $unique_key_arr = 'uuid';

    /** 
     * 单例实例
     */
    static public $instance = null;

    /**
     * @return MemberModel|null
     * @throws ModelSqlException
     */
    static public function getInstance() {
        if(is_null(self::$instance)){
            self::$instance = new self();
        }
        return self::$instance;
    }

    /**
     * MemberModel constructor.
     * @throws ModelSqlException
     */
    public function __construct() {
        parent::__construct(str_replace("Model", "", substr(get_class($this), strrpos(get_class($this), "\\")+1)));
        $this->meta = new \stdClass();
    }

    /**
     * @throws ModelException
     */
    public function __clone() {
        throw new ModelException(
            str_replace('%s', get_class($this), ModelException::INSTANCE_NOT_ALLOW_TO_CLONE), ModelException::INSTANCE_NOT_ALLOW_TO_CLONE_NO);
    }

    public function __destruct() {
        self::$instance = null;
    }

    /**
     * set属性
     *
     * __set. 
     * @param string $name 参数名
     * @param string $value 参数值
     * @return $this
     */
    public function __set($name = "", $value = "") {
        $this->$name = $value;
        return $this;
    }

    /**
     * get属性
     *
     * __get. 
     * @param string $name 参数名
     * @return mixed
     */
    public function __get($name = "") {
        return  $this->$name ;
    }

    /**
     * 创建memberModel
     * 
     * @return mixed
     * @throws ModelDriverException
     * @throws ModelReflectionException
     * @throws ModelSqlException
     * @throws ModelException
     */
    public function insert() {
        return $this->insertRecord();
    }

    /**
     * 编辑memberModel
     * 
     * @return mixed
     * @throws ModelDriverException
     * @throws ModelReflectionException
     * @throws ModelSqlException
     * @throws ModelException
     */
    public function update() {
        return $this->updateRecord();
    }

    /**
     * 删除memberModel，需先指定主键
     * 
     * @return mixed
     * @throws ModelDriverException
     * @throws ModelReflectionException
     * @throws ModelSqlException
     * @throws ModelException
     */
    public function delete() {
        return $this->deleteRecord();
    }

    /**
     * 根据主键查询memberModel，获取单条记录
     *
     * find. 
     * @param int $primary_key 主键编号
     * @return $this
     * @throws ModelException
     * @throws ModelReflectionException
     */
    public function find($primary_key = 0) {
        $result = $this->findByPrimaryKey($primary_key);

        $this->setModelProperty($result);

        return $this;
    }

    /**
     * 根据条件数组查询memberModel，获取多条记录
     *
     * findOneBy. 
     * @param array $condition 查询条件
     * @return $this
     * @throws ModelDriverException
     * @throws ModelException
     * @throws ModelReflectionException
     * @throws ModelSqlException
     */
    public function findOneBy($condition = []) {
        $result = $this->findRecordBy($condition);

        $this->setModelProperty($result);

        return $this;
    }

    /**
     * 根据条件数组查询memberModel，获取多条记录
     *
     * findBy. 
     * @param array $condition 查询条件
     * @return $this
     * @throws ModelDriverException
     * @throws ModelException
     * @throws ModelReflectionException
     * @throws ModelSqlException
     */
    public function findBy($condition = []) {
        $count = $this->getCount($condition);
        $total = $count->fetchColumn();

        $this->data = [];
        $memb_obj = $this->findRecordBy($condition, $this->page, $this->page_size);

        $this->genMeta($total);
        $this->setModelProperty($memb_obj, true);

        return $this;
    }

    /**
     * 批量插入memberModel
     * 
     * @return mixed
     * @throws ModelDriverException
     * @throws ModelException
     * @throws ModelSqlException
     */
    public function batchInsert() {
        return $this->batchInsertRecord();
    }

    /**
     * 批量删除memberModel
     * 
     * @throws ModelDriverException
     * @throws ModelException
     * @throws ModelSqlException
     */
    public function batchDelete() {
        $this->batchDeleteRecord();
    }

    /**
     * 生成批量生成update的sql
     * 
     * @return bool|string
     * @throws ModelDriverException
     * @throws ModelException
     * @throws ModelSqlException
     */
    public function genBatchUpdateSql() {
        return $this->_genBatchUpdateSql();
    }

}